package com.wd.live.module_base.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.wd.live.module_base.R;


/**
 * 功能:组合式控件-搜索栏
 */
public class BaseSearch extends ConstraintLayout {
    private EditText editId;
    private ImageView btnSearch;
    private ConstraintLayout consId;

    public BaseSearch(@NonNull Context context) {
        super(context);
    }
    public BaseSearch(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        //加载布局
        View.inflate(context, R.layout.item_search, this);
        //使用控件方法
        initView();
        //接口回调
        editId.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                //判断不为空 则调用
                if (onClick!=null){
                    onClick.onClick();
                }
            }
        });

//        consId.setOnClickListener(new OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                if (onClick != null) {
//                    onClick.onClick();
//                }
//
//            }
//        });



    }

    //提示 Hint的方法
    public void setHint(String key){
        editId.setHint(key);
    }

    //接口回调的方法
    public interface OnClick {
        void onClick();
    }

    //声明
    public OnClick onClick;

    //set方法
    public void setEditId(EditText editId) {
        this.editId = editId;
    }

    public EditText getEditId() {
        return editId;
    }

    public ImageView getBtnSearch() {
        return btnSearch;
    }

    public void setBtnSearch(ImageView btnSearch) {
        this.btnSearch = btnSearch;
    }

    public ConstraintLayout getConsId() {
        return consId;
    }

    public void setConsId(ConstraintLayout consId) {
        this.consId = consId;
    }

    public OnClick getOnClick() {
        return onClick;
    }

    public void setOnClick(OnClick onClick) {
        this.onClick = onClick;
    }

    private void initView() {
        editId = (EditText) findViewById(R.id.search_edit_id);
        btnSearch = (ImageView) findViewById(R.id.btn_search_id);
        consId = (ConstraintLayout) findViewById(R.id.search_cons_id);
    }
}
